﻿using System.Collections.Generic;
using IQIGame.Onigao.Logic;

namespace IQIGame.Onigao.GamePlay
{
    public partial class DynLevelPlayer : IConditionPropFetcher
    {
        private LevelPlayRegionController regionCtrl => LevelPlayModule.Instance.levelPlay.regionCtrl;

        public int FetchConditionProp(ConditionBlackboard blackboard, int iType, IReadOnlyList<int> curValueParams)
        {
            ConditionCurPlayerPropType type = (ConditionCurPlayerPropType)iType;
            DynLevelPlayer levelPlayer = (DynLevelPlayer)blackboard.curPlayer;
            switch (type)
            {
                case ConditionCurPlayerPropType.IsEntityFollowHero:
                    int entityMcid = curValueParams[0];
                    if (entityMcid <= 0) //是否被任意实体跟随
                    {
                        return levelPlayer.followerId != 0 ? 1 : 0;
                    }
                    //是否被指定实体跟随
                    int fid = levelPlayer.followerId;
                    if (fid != 0 && regionCtrl.entityCtrl.entitys.TryGetValue(fid, out var e))
                    {
                        return e.GetDynLevelEntity().mcid == entityMcid ? 1 : 0;
                    }
                    return 0;
                case ConditionCurPlayerPropType.IsQuestInProgress:
                    int questCid1 = curValueParams[0];
                    bool v1 = GameDataCenter.PlayerData.quest.ContainsKey(questCid1);
                    return v1 ? 1 : 0;
                case ConditionCurPlayerPropType.IsQuestFinished:
                    int questCid2 = curValueParams[0];
                    bool v2 = GameDataCenter.PlayerData.quest.IsInSuccess(questCid2);
                    return v2 ? 1 : 0;
                case ConditionCurPlayerPropType.HaveBuff:
                    int buffCid = curValueParams[0];
                    return levelPlayer.buffHolder.ContainsBuff(buffCid) ? 1 : 0;
                default:
                    LogicLog.LogError($"关卡视图层不支持的条件类型：2 - {iType}");
                    return 0;
            }
        }
    }
}
